import requests
import sys
import logging
from common import presignedUrl
from xml.etree import ElementTree

# 正常情况日志级别使用INFO，需要定位时可以修改为DEBUG，此时SDK会打印和服务端的通信信息
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# 扫描s3中的二维码图片
def scanQRCode(key):
    # 请求参数
    params = {
        "ci-process": "QRcode",
        "cover": 0,
    }
    codeUrl = ""
    url = presignedUrl.getPresignedUrl(key, "GET", params)
    res = requests.get(url=url)
    if res.status_code == 200:

        root = ElementTree.fromstring(res.text)
        codeStatus = root.getchildren()[0].text
        if int(codeStatus) == 1:
            QRCodeInfo = root.getchildren()[1]
            codeUrl = QRCodeInfo.getchildren()[0].text
    return codeUrl
